#include "TmxHandler.hpp"
#include <GQE/Core/loggers/Log_macros.hpp>
#include <GQE/Entity/classes/Instance.hpp>
#include <GQE/Entity/classes/Prototype.hpp>
TmxHandler::TmxHandler() :
  GQE::TAssetHandler<Tmx::Map>()
{
  ILOG() << "TmxHandler::ctor()" << std::endl;
}

TmxHandler::~TmxHandler()
{
  ILOG() << "TmxHandler::dtor()" << std::endl;
}

bool TmxHandler::LoadFromFile(const GQE::typeAssetID theAssetID, Tmx::Map& theMap)
{
  // Start with a return result of false
  bool anResult = false;

  // Retrieve the filename for this asset
  std::string anFilename = GetFilename(theAssetID);
  // Was a valid filename found? then attempt to load the asset from anFilename
  if(anFilename.length() > 0)
  {
    theMap.ParseFile(anFilename);
    if(!theMap.HasError())
    {
      anResult=true;
    }
    else
    {
      ILOG() << "Error Loading Tmx File. Error Code: "<<theMap.GetErrorCode()<<std::endl;
    }

  }
  else
  {
    ELOG() << "TmxHandler::LoadFromFile(" << theAssetID
      << ") No filename provided!" << std::endl;
  }

  // Return anResult of true if successful, false otherwise
  return anResult;
}

bool TmxHandler::LoadFromMemory(const GQE::typeAssetID theAssetID,Tmx::Map& theMap)
{
  // Start with a return result of false
  bool anResult = false;

  // TODO: Retrieve the const char* pointer to load data from
  const char* anData = NULL;
  // TODO: Retrieve the size in bytes of the font to load from memory
  size_t anDataSize = 0;

  // Try to obtain the font from the memory location specified
  if(NULL != anData && anDataSize > 0)
  {

  }
  else
  {
    ELOG() << "TmxHandler::LoadFromMemory(" << theAssetID
      << ") Bad memory location or size!" << std::endl;
  }

  // Return anResult of true if successful, false otherwise
  return anResult;
}

bool TmxHandler::LoadFromNetwork(const GQE::typeAssetID theAssetID, Tmx::Map& theMap)
{
  // Start with a return result of false
  bool anResult = false;

  // TODO: Add load from network for this asset

  // Return anResult of true if successful, false otherwise
  return anResult;
}
